package com.design.pattern.principle.dependencyInversion.improve.dependCase2;

public class DependCase1 {
    public static void main(String[] args) {
        //通过构造器进行依赖的传递
        new OpenAndClose(new ChangHong()).open();
    }
}

/**
 * 通过构造方法传递依赖，开发中应该也是见过的
 */
interface IOpenAndClose {
    void open();
}

class ChangHong implements ITV {

    @Override
    public void play() {
        System.out.println("长虹电视机。打开");
    }
}


interface ITV {
    void play();
}

class OpenAndClose implements IOpenAndClose {
    private ITV tv;

    public OpenAndClose(ITV tv) {
        this.tv = tv;
    }

    @Override
    public void open() {
        this.tv.play();
    }
}
